home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 076-100 / 084 / blitlab / blitlab.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  5KB  |  184 lines

  1. /*
  2.  *   This is the main routine from BlitLab.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   Here are all the globals we use.  (Yuck!  Globals!)
  7.  */
  8. struct Window *mywindow ;
  9. struct GfxBase *GfxBase ;
  10. struct IntuitionBase *IntuitionBase ;
  11. struct RastPort *myrp ;
  12. char strings[900] ;
  13. char *bufarr[MAXGADG] ;
  14. long gvals[MAXGADG] ;
  15. struct Gadget *gadgets[MAXGADG] ;
  16. char errorbuf[140] ;
  17. short *realbits ;
  18. struct blitregs blitregs ;
  19. int errortitle ;
  20. /*
  21.  *   Externals we use:
  22.  */
  23. extern int blitsafe() ;
  24. /*
  25.  *   Some statics to this module.
  26.  */
  27. static int updatethem ;
  28. /*
  29.  *   Errors go through here.  Currently, we write to the CLI window.
  30.  *   Later, we will write to the title bar of the window.
  31.  */
  32. error(s)
  33. char *s ;
  34. {
  35.    if (mywindow == NULL || *s == '!')
  36.       printf("blitlab: %s\n", s) ;
  37.    else {
  38.       SetWindowTitles(mywindow, s, -1L) ;
  39.       errortitle = 1 ;
  40.    }
  41.    if (*s == '!')
  42.       cleanup() ;
  43. }
  44. /*
  45.  *   This routine handles a gadget selection.
  46.  */
  47. handlegadget(gp)
  48. register struct Gadget *gp ;
  49. {
  50.    static int gocount = 0 ;
  51.  
  52.    if (errortitle == 1) {
  53.       SetWindowTitles(mywindow, BANNER, -1L) ;
  54.       errortitle = 0 ;
  55.    }
  56.    if (bufarr[gp->GadgetID] == NULL)
  57.    switch(gp->GadgetID) {
  58.       case GDGPNTREG:
  59.       case GDGCLRSET:
  60.       case GDGLINE:
  61.       case GDGDESC:
  62.       case GDGFCI:
  63.       case GDGIFE:
  64.       case GDGEFE:
  65.       case GDGUSEA:
  66.       case GDGUSEB:
  67.       case GDGUSEC:
  68.       case GDGUSED:
  69.       case GDGOVF:
  70.       case GDGSIGN:
  71.          flipgadg(gp->GadgetID) ;
  72.          break ;
  73.       case GDGCALC:
  74.          parseall() ;
  75.          updatethem = 0 ;
  76.          if (!blitsafe()) {
  77.             error("Blit unsafe.") ;
  78.          }
  79.          break ;
  80.       case GDGSETUP:
  81.          setupline() ;
  82.          parseall() ;
  83.          break ;
  84.       case GDGGO:
  85.          gocount += 2 ;
  86.          parseall() ;
  87.          updatethem = 0 ;
  88.          if (!blitsafe()) {
  89.             if (gocount < 3)
  90.                error("Blit unsafe---hit again to override") ;
  91.             else {
  92.                doblit() ;
  93.                updatebits() ;
  94.             }
  95.          } else {
  96.             doblit() ;
  97.             updatebits() ;
  98.          }
  99.          break ;
  100.       default:
  101.          error("! bad value in gadget switch") ;
  102.          break ;
  103.    }
  104.    if (gocount > 0)
  105.       gocount-- ;
  106. }
  107. /*
  108.  *   The main routine, no arguments.  Sets things up, and then goes
  109.  *   through the standard Intuition message loop.
  110.  *
  111.  *   It may look like I'm setting message to NULL and checking it and
  112.  *   everything all over, but that is so I can introduce interruptibility
  113.  *   into some operations later, if I choose.
  114.  */
  115. main() {
  116.    struct IntuiMessage *message = NULL ;
  117.    int x, y ;
  118.    int mousemoved = 0 ;
  119.    int getouttahere = 0 ;
  120.    int selectdown = 0 ;
  121.    int bam ;
  122.    int ox, oy ;
  123.  
  124.    initialize() ;
  125.    while (1) {
  126.       mousemoved = 0 ;
  127.       bam = 0 ;
  128.       if (message == NULL)
  129.          WaitPort(mywindow->UserPort) ;
  130.       while (message || (message = 
  131.                        (struct IntuiMessage *)GetMsg(mywindow->UserPort))) {
  132.          x = message->MouseX ;
  133.          y = message->MouseY ;
  134.          if (message->Class == MOUSEMOVE) {
  135.             ReplyMsg(message) ;
  136.             message = NULL ;
  137.             mousemoved = 1 ;
  138.          } else {
  139.             if (message->Class == MOUSEBUTTONS) {
  140.                selectdown = (message->Code == SELECTDOWN) ;
  141.                bam = 1 ;
  142.             } else if (message->Class == GADGETDOWN || 
  143.                        message->Class == GADGETUP) {
  144.                updatethem = 1 ;
  145.                handlegadget((struct Gadget *)(message->IAddress)) ;
  146.             } else if (message->Class == CLOSEWINDOW) {
  147.                getouttahere = 1 ;
  148.             } else
  149.                error("! undefined message class") ;
  150.             ReplyMsg(message) ;
  151.             message = NULL ;
  152.          }
  153.       }
  154.       if (getouttahere)
  155.          break ;
  156.       if (updatethem) {
  157.          parseall() ;
  158.          updatethem = 0 ;
  159.       }
  160.       x = (x - HBITSTART) / 6 ;
  161.       y = (y - VBITSTART) / 3 ;
  162.       if (y < 32 && x < 96 && x >= 0 && y >= 0) {
  163.          if (gvals[GDGPNTREG]) {
  164.             if (bam) {
  165.                if (selectdown) {
  166.                   ox = x ;
  167.                   oy = y ;
  168.                } else {
  169.                   preg(ox, oy, x, y, (int)gvals[GDGCLRSET]) ;
  170.                }
  171.             }
  172.          } else {
  173.             if (selectdown)
  174.                pdot(x, y, (int)gvals[GDGCLRSET]) ;
  175.          }
  176.          if (message != NULL || (message = 
  177.                (struct IntuiMessage *)GetMsg(mywindow->UserPort))) ;
  178.          else
  179.             updatepos(x, y) ;
  180.       }      
  181.    }
  182.    cleanup() ;
  183. }
  184.